import { Tool } from '../../../Tool';

/**
 * 构件定位
 */
export class ComponentPositionTool extends Tool {
	constructor(viewer) {
		super(arguments);
		this.viewer = viewer;
		this.handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
	}

	start() {
		this.handler.setInputAction((e) => {
			const pick = this.viewer.scene.pick(e.position);
			if (!pick) return;
			const layer = pick?.primitive;
			// const layer = this.viewer.scene.layers.getSelectedLayer()
			this.viewer.flyTo(layer, { duration: 0.6 });
		}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
	}

	cancel() {
		this.handler?.destroy();
	}
}
ComponentPositionTool.toolId = 'ComponentPositionTool';
